package com.project.service.impl;


import com.project.bean.CutPageBean;
import com.project.bean.StudentBean;
import com.project.mapper.IStudentMapper;
import com.project.service.IStudentService;

import java.time.LocalDate;
import java.util.List;

public class IStudentServiceImpl extends BaseService implements IStudentService {
    @Override
    public void add(StudentBean student) {
        IStudentMapper mapper = session.getMapper(IStudentMapper.class);
        mapper.add(student);
        this.commitAndClose();
    }

    @Override
    public void del(int id) {
        IStudentMapper mapper = session.getMapper(IStudentMapper.class);
        mapper.del(id);
        this.commitAndClose();
    }

    @Override
    public CutPageBean findByStudent(int pageNo,String name, String classroom, String address) {
        IStudentMapper mapper = session.getMapper(IStudentMapper.class);
        this.flag=false;
        CutPageBean<StudentBean> cutPageBean = new CutPageBean<StudentBean>();
        cutPageBean.setList(mapper.cutByItem(name,classroom,address,
                (pageNo-1)* CutPageBean.PAGESIZE,CutPageBean.PAGESIZE));
        cutPageBean.setCount(mapper.cuntByCount(name,classroom,address));
        this.commitAndClose();
        return cutPageBean;
    }

    @Override
    public StudentBean findById(int id) {
        this.flag=false;
        IStudentMapper mapper = session.getMapper(IStudentMapper.class);
        StudentBean stu =  mapper.findById(id);
        this.commitAndClose();
        return stu;
    }

    @Override
    public void update(int id, int roomId) {
        IStudentMapper mapper = session.getMapper(IStudentMapper.class);
        mapper.update(id,roomId);
        this.commitAndClose();
    }
    public static void main(String[] args){
        IStudentService service = new IStudentServiceImpl();
//        service.add(new StudentBean("王老五","男",1,
//                1,"13880905215", LocalDate.parse("2020-09-10"),"0000"));
//        service.del(17);
//        System.out.println(service.findById(9));
//        service.update(16,2);
//        IStudentMapper mapper = session.getMapper(IStudentMapper.class);
//        System.out.println(mapper.findLikeId(2));
        System.out.println(service.findByStudent(1,"孙","A","A"));

    }
}
